from manim import *



class math1(MovingCameraScene):
    def construct(self):
        self.camera.background_color = BLACK  # 设置背景颜色
        self.camera.frame_width = 100  # 设置边框宽度
        self.camera.frame_height = 60  # 设置边框高度
        self.camera.pixel_height = 1080  # 设置像素高度
        self.camera.pixel_width = 1920  # 设置像素宽度
        self.camera.center = ORIGIN  # 设置中心点位置
        self.camera.scale_factor = 1.0  # 设置缩放因子
        #设置横线
        for i in range(6*2+1):       
            dot1=Dot([-50,5*(i-6),0]).set_opacity(0.5)
            dot2=Dot([50,5*(i-6),0]).set_opacity(0.5)
            if i==6:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
                
            else:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
               
            self.add(dot1,dot2,line1)
        #设置竖线
        for i in range(10*2+1):        
            dot3=Dot([(i-10)*5,-30,0]).set_opacity(0.5)
            dot4=Dot([(i-10)*5,30,0]).set_opacity(0.5)
            if i==10:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
                
            else:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
            self.add(dot3,dot4,line2)
        #设置三个点
        dot1 = Dot(radius=1, color=RED)  
        dot1.move_to([-47.5,27.5,0]) 
        dot2 = Dot(radius=1, color=YELLOW)  
        dot2.move_to([-42.5,27.5,0])  
        dot3 = Dot(radius=1, color=GREEN)  
        dot3.move_to([-37.5,27.5,0])
        #镜头跟进效果 
        self.camera.frame.save_state()
        #题目出现
        text = Tex(r"\text{设}$f\left( x\right) $\text{在区间}$\left[ 0,1\right] $\text{可导,}$f\left( 0\right) =0,f\left( 1\right) =1,$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0)
        text1 = Tex(
                   r"\text{且}$f\left( x\right) $\text{不恒等于x.证明：存在}$\xi \in \left( 0,1\right) ,$\text{使得}$f'\left( \xi \right)  >1$"
                 ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,-5,0])
        '''
        text2 = Tex(
                    r"\text{(2)若当}$0 <x <1$\text{时,}$f'\left( x\right) \neq 2,$\text{则}$\int _{0}^{x}f\left( t\right) dt >x^{2}$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-11,-10,0])
        text3 = Tex(
                   r"\text{,证明：}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text,RIGHT,buff=1)
        '''
        self.play(Write(text),self.camera.frame.animate.scale(0.8),Write(text1))#,Write(text2),Write(text3))
        self.wait()
        #镜头拉回
          #分析文本
        #text100=MarkupText("<b><i>分析/解：</i></b>",color=PINK).scale(5.0).move_to([-38,12.5,0])
        self.play(Restore(self.camera.frame))
        self.play(FadeIn(dot1),run_time=0.1)
        self.play(FadeIn(dot2),run_time=0.1)
        self.play(FadeIn(dot3),run_time=0.1)
        #题目向上移动
        self.play(text.animate().move_to([0,20,0]),text1.animate().move_to([0,15,0]))# ,text2.animate().move_to([-11,10,0]),text3.animate().move_to([44,20,0]) )

        #两种方法介绍
        text2 = Tex(r"\text{1.构造辅助函数}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(6.0).move_to([-25,0,0])
        arrow = Arrow(start=[-12,0,0],end=[15,0,0],color=RED
                       , stroke_width=20, tip_length=1)
        self.play(Write(text2))
        self.play(GrowArrow(arrow))
        text3 = Tex(r"\text{形成新不等式}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(6.0).move_to([25,0,0])
        text300 = Tex(r"\text{单调性}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(6.0).move_to([0,5,0])
        self.play(Write(text3),Write(text300))
        text4 = Tex(r"\text{2.两边积分}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(6.0).move_to([-25,-10,0])
        arrow1 = Arrow(start=[-15,-10,0],end=[15,-10,0],color=RED
                       , stroke_width=20, tip_length=1)
        self.play(Write(text4))
        self.play(GrowArrow(arrow1))
        text5 = Tex(r"\text{形成新不等式}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(6.0).move_to([25,-10,0])
        self.play(Write(text5))

        #清空介绍

        self.play(Uncreate(text2),Uncreate(text3),Uncreate(text300),Uncreate(text4),Uncreate(text5)
                  ,Uncreate(arrow),Uncreate(arrow1))

        #镜头拉近
        self.play(self.camera.frame.animate.scale(0.8).move_to([25,10,0]))
        #箭头
        #箭头引出+框框标记
        arrow2 = Arrow(start=[32.5,20,0],end=[27,18,0], color=RED
                       , stroke_width=20, tip_length=1)
        long_text=("特征识别:\n"
                     "中值不等式")
        text6 = Text(long_text,color=YELLOW,
                   font_size=200).move_to([42,20,0])
        self.play(Create(arrow2))

        rectangle=Rectangle(color=BLUE,fill_opacity=0.0,width=11,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle.move_to([26, 15, 0])
        self.play(Create(rectangle),Write(text6))

        #箭头引出

        arrow3 = Arrow(start=[26,11,0],end=[26,2,0], color=RED
                       , stroke_width=20, tip_length=1)
        self.play(GrowArrow(arrow3),self.camera.frame.animate.move_to([25,-3,0]))

        text7 = Tex(r"\text{反证法}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(6.0).move_to([26,-3,0])
        self.play(Write(text7))

        text8 = Tex(r"\text{假设}$f'\left( x\right) \leq 1  ( 0 <x < 1) $",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(6.0).move_to([26,-8,0])
        self.play(Write(text8))


        #箭头引出+框框标记
        arrow4 = Arrow(start=[12.5,-1,0],end=[17,-5,0], color=RED
                       , stroke_width=20, tip_length=1)
        long_text=("特征识别:\n"
                     "导数不等式")
        text9 = Text(long_text,color=YELLOW,
                   font_size=200).move_to([2,0,0])
        self.play(Create(arrow4))

        rectangle1=Rectangle(color=BLUE,fill_opacity=0.0,width=13,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle1.move_to([21, -8, 0])
        self.play(Create(rectangle1),Write(text9))

        #箭头引出

        arrow5 = Arrow(start=[21,-11,0],end=[21,-16,0], color=RED
                       , stroke_width=20, tip_length=1)
        self.play(GrowArrow(arrow5),self.camera.frame.animate.move_to([21,-20,0]))

        text10 = Tex(r"\text{构造辅助函数利用单调性}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(6.0).move_to([21,-20,0])
        self.play(Write(text10))
        self.play(Restore(self.camera.frame))

        text11 = Tex(r"\text{令}$F\left( x\right) =f\left( x\right) -x(0<x<1)$",color=RED_B
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-30,10,0])
        self.play(Write(text11))

        text12 = Tex(r"\text{则}$F'\left( x\right)  <=0(F\left( x\right) \downarrow )$",color=BLUE_B
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-30,5,0])
        self.play(Write(text12))
        text13 = Tex(r"$F\left( 0\right) \geq F\left( x\right) \geq F\left( 1\right) $",color=YELLOW_B
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-30,0,0])
        self.play(Write(text13))

        text14 = Tex(r"$0$",color=PURE_GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-40,-5,0])
        self.play(Write(text14))
        text15 = Tex(r"$0$",color=PURE_GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-20,-5,0])
        self.play(Write(text15))

        text16 = Tex(r"$F\left( x\right) =0$",color=PURE_GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-30,-10,0])
        self.play(Write(text16))

        text17 = Tex(r"$f\left( x\right) =x$",color=PURE_RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-30,-15,0])
        self.play(Write(text17))

        #框框标记
        #半透明矩阵扩展
        rectangle4=Rectangle(color=BLUE,fill_opacity=0.5,width=1,height=2.8
                            ,stroke_color=YELLOW,stroke_width=0).move_to([-20,15,0])
        self.play(
            rectangle4.animate.stretch(20.0,dim=0)
        )

        #清空部分元素
        self.play(Uncreate(text17),Uncreate(text16),Uncreate(text15),Uncreate(text14)
                  ,Uncreate(text13),Uncreate(text12),Uncreate(text11),
                  FadeOut(rectangle4))
        text18 = Tex(r"\text{两边积分}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(6.0).move_to([21,-20,0])
        self.play(self.camera.frame.animate.move_to([26, 15, 0]))
        self.play(self.camera.frame.animate.move_to([21,-20,0]),run_time=3)

        #文本丝滑变化
        self.play(
            ReplacementTransform(text10,text18)
        )
        self.wait(0.5)
        self.play(Restore(self.camera.frame))

        text19 = Tex(r"$\int _{0}^{1}f'\left( x\right) dx\leq \int ^{1}_{0}1dx$",color=RED_B
                   ,tex_template=TexTemplateLibrary.ctex).scale(6.0).move_to([-30,0,0])
        self.play(Write(text19))
        #箭头
        arrow5 = Arrow(start=[-22,-5,0],end=[-27,-3,0], color=RED
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow5))
        #框框标记
        #半透明矩阵扩展
        rectangle4=Rectangle(color=BLUE,fill_opacity=0.5,width=1,height=2.8
                            ,stroke_color=YELLOW,stroke_width=0).move_to([-20,15,0])
        self.play(
            rectangle4.animate.stretch(20.0,dim=0)
        )
        self.play(FadeOut(rectangle4))

        text20 = Tex(r"$\int _{0}^{1}f'\left( x\right) dx <\int ^{1}_{0}1dx$",color=BLUE_B
                   ,tex_template=TexTemplateLibrary.ctex).scale(6.0).move_to([-30,0,0])
        #文本丝滑变化
        self.play(
            ReplacementTransform(text19,text20),FadeOut(arrow5)
        )
        self.wait(0.5)

        text21 = Tex(r"$1$",color=PURE_GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(6.0).move_to([-40,-5,0])
        self.play(Write(text21))
        text22 = Tex(r"$1$",color=PURE_GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(6.0).move_to([-20,-5,0])
        self.play(Write(text22))

        #清空屏幕
        self.clear()
        #文本

        text0 = Tex(r"\text{(2018)设函数}$f\left( x\right) $\text{在}$\left[ 0,1\right] $\text{二阶可导,且}$\int _{0}^{1}f\left( x\right) dx=0$\text{则()}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,0,0])
        text1 = Tex(
                   r"\text{(A)当}$f'\left( x\right)  <0$\text{时,}$f\left( \dfrac{1}{2}\right)  <0$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-22,-5,0])
        text2 = Tex(
                    r"\text{(B)当}$f''\left( x\right)  <0$\text{时,}$f\left( \dfrac{1}{2}\right)  <0$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([22,-5,0])
        text3 = Tex(
                   r"\text{(C)当}$f'\left( x\right)  >0$\text{时,}$f\left( \dfrac{1}{2}\right)  <0$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-22,-12,0])
        text4 = Tex(
                    r"\text{(D)当}$f''\left( x\right)  >0$\text{时,}$f\left( \dfrac{1}{2}\right)  <0$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([22,-12,0])

        self.play(Write(text0),self.camera.frame.animate.scale(0.8),Write(text1),Write(text2),Write(text3),Write(text4))
        self.wait(0.1)












        
        self.play(Restore(self.camera.frame))
        self.wait()